
var isGuide=window.localStorage.getItem("isGuide")
// 加载页面
  if (!isGuide) {
    $('.guide-page').show();
  }else{
     $('.guide-page').hide();
  }
function guide_page(){
  var window_width=$('.guide-page').width();
  var window_height=$('.guide-page').height();
  $('.guide').css('marginTop',(window_height-$('.guide').height()-80)/2);
  $('.swipe-wrap div').width(window_width);
  $('.swipe-wrap div').height(window_height);
  $('.xiaodian').css('left',(window_width-$('.xiaodian').width())/2+'px');
  var elem = document.getElementById('guide-page');
  window.mySwipe = Swipe(elem, {
      startSlide: 0,
      auto:false,
      continuous: false,
      disableScroll: false,
      stopPropagation: false,
      callback: function(index, element) {
        $('.xiaodian').find('li').eq(index).addClass('active').siblings('li').removeClass('active');
      },
      transitionEnd: function(index, element) {
      }
    });
}
guide_page();
 // 页面加载完执行图片轮播
    function seteWidth(){
      var window_width=$('.swipe').width();
      var window_height=$('.swipe').find('img').height();
      $('.swipe').height(window_height+'px')
      $('.swipe').find('img').width(window_width+'px');
      var dots_width=$('.dots').width();
      $('.dots').css('left',(window_width-dots_width)/2);
      var elem = document.getElementById('mySwipe');
      $('.dots').find('li').eq(0).addClass('act');
      window.mySwipe = Swipe(elem, {
          startSlide: 0,
          auto: 3000,
          continuous: true,
          disableScroll: true,
          stopPropagation: true,
          callback: function(index, element) {
            $('.dots').find('li').eq(index).addClass('act').siblings('li').removeClass('act');
          },
          transitionEnd: function(index, element) {
          }
        });
     }
// 小贝头条点击获取ID 跳转详情页面
function obtainId(even){
  var News_id=$(even).attr('data-id');
    window.localStorage.setItem("News_id",News_id);
    window.location.href='More/M-News-details.html'; 
}
$(function(){ 
  $('.index-bnt').click(function(){
   $('.guide-page').hide();
  window.localStorage.setItem("isGuide",true);
  })
  // 储存加载状态
    window.localStorage.setItem("isGuide",false);
    //定义小北新闻 宽度
     function setWidth(){
      var xsb_width=$(".xiaobei").width();
      var windw_width=$(".Journalism").width();
      $('#Journalism').width(windw_width-xsb_width-30+'px');
     }
  setWidth()
      //小贝头条新闻上下轮播
      function autoScroll(){
            $(".newsBox").find("ul").css({'transform':'translate(0,-14px)','transition-duration':'1s'});
            setTimeout(function(){
              $(".newsBox").find("ul").find("li:first").appendTo('.newsBox ul');
              $(".newsBox").find("ul").css({'transform':'translate(0,0)','transition-duration':'0s'});
              //性能 
            },1000)
      };
        setInterval(function(){
          autoScroll();
        },3000);
    //判断状态
    function setLogin(){
      ajaxRequest('/api/homePage/nav',null,function(data){
      // $('.LoadAnimaNew').remove();
        // 登录显示消息栏;
        if(data.data.user_name){
              $('.login').hide();
             $('.prompt').show();
             if(!data.data.num){
                 $('.prompt .number').hide();
             }else{
                 $('.prompt .number').show().text(data.data.num);
             }
         }else{
             $('.login').show();
             $('.prompt').hide();
         };
          // 获取新闻信息;
              var JournalismShow="";
              for (var i=0; i<data.data.news.length;i++) {
                  JournalismShow +='<li data-id="'+data.data.news[i].id+'" onclick="obtainId(this)">'+data.data.news[i].title+'</li>'
              }
              $(JournalismShow).appendTo('.JournalismShow');
             //banner图 获取；
             var banner_len="";
             var dots_len="";
             var Journalism="";
             for (var i=0;i<data.data.navs.length;i++) {
                banner_len += '<div><a href="Activity/activitynew.html"'+data.data.navs[i].link+'"><img onload=\"seteWidth()\" src="'+contextPath+data.data.navs[i].image+'"></a></div>'
                // 自动添加小圆点
                dots_len +='<li></li>';
             }
             $(banner_len).appendTo('#mySwipe .swipe-wrap');
              $(dots_len).appendTo('.dots');
      },true);
    }
     //下拉加载  上拉刷新//
     var projectsNuber=0;
    // dropload
    $('.page-box').dropload({
        scrollArea : window,
        loadDownFn : function(me){
          ajaxRequest('/api/homePage/projects/'+projectsNuber+'',null,function(data){
            // 判断是否加载完毕
            if(!data.data.r_projects){
               // 锁定
                me.lock();
              // 无数据
              me.noData();
            }
            $(data.data.r_projects).appendTo('.notice-list');
            projectsNuber++
            me.resetload();
          },false);  
        },
        threshold :50
    });
    var password=window.localStorage.getItem("password");
    var phone_number=window.localStorage.getItem("phone_number");
    if(password && phone_number){
      var userdata={'phone_number':phone_number,'password':password}
      ajaxRequest('/api/login/',userdata,function(data){
        if (data.m_status==200) {
          setLogin()
        }
      },false);
    }else{
      setLogin()
    }
});
